"""
文本类模块
"""
import pygame
from text.operations import draw_text


class Text(object):
    """
    文本类
    """

    def __init__(
            self,
            text: str,
            target: pygame.Surface | None,
            position: tuple[int, int] = (0, 0),
            is_h_center: bool = False,
            is_v_center: bool = False,
            text_color: tuple[int, int, int] | tuple[int, int, int, int] | str = (0, 0, 0),
            text_color_active: tuple[int, int, int] | tuple[int, int, int, int] | str = (0, 0, 0),
            font_name: str = 'Microsoft YaHei UI',
            font_size: int = 16,
            font_bold: bool = False,
            font_italic: bool = False,
    ):
        """
        文本类对象的初始化方法
        :param text: 文本内容字符串
        :param target: 文本要绘制到的 Surface 对象
        :param position: 文本在目标 Surface 对象中的绘制位置
        :param is_h_center: 文本是否在目标 Surface 对象中水平居中
        :param is_v_center: 文本是否在目标 Surface 对象中垂直居中
        :param text_color: 文本文字颜色
        :param text_color_active: 文本文字激活颜色
        :param font_name: 文本字体名称
        :param font_size: 文本字体大小
        :param font_bold: 文本字体是否加粗
        :param font_italic: 文本字体是否倾斜
        """
        self.text = text
        self.target = target
        self.position = position
        self.is_h_center = is_h_center
        self.is_v_center = is_v_center
        self.text_color = text_color
        self.text_color_active = text_color_active
        self.is_active = False
        self.font_name = font_name
        self.font_size = font_size
        self.font_bold = font_bold
        self.font_italic = font_italic

    def draw(self):
        """
        绘制文本
        :return:
        """
        text_color = self.text_color
        if self.is_active:
            text_color = self.text_color_active
        draw_text(
            self.text,
            self.target,
            self.position,
            self.is_h_center,
            self.is_v_center,
            text_color,
            self.font_name,
            self.font_size,
            self.font_bold,
            self.font_italic
        )
